package com.weipu.common.facade.model;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONObject;

/************************
 * @author Tony
 * @Date:2016-3-29下午2:31:20
 * @描述:一键过滤接口的返回数据模型
 ************************/
public class OneKeyFilterResponseModel {
	//用户CID
	private long customerID;
	//是否开启过滤
	private boolean isFilter;
	//品类白名单
	private List<CatelogModel> whiteCategoryData;
	//品类黑名单
	private List<CatelogModel> blackCategoryData;
	
	
	public long getCustomerID() {
		return customerID;
	}
	public void setCustomerID(long customerID) {
		this.customerID = customerID;
	}
	public boolean isFilter() {
		return isFilter;
	}
	public void setFilter(boolean isFilter) {
		this.isFilter = isFilter;
	}
	public List<CatelogModel> getWhiteCategoryData() {
		return whiteCategoryData;
	}
	public void setWhiteCategoryData(List<CatelogModel> whiteCategoryData) {
		this.whiteCategoryData = whiteCategoryData;
	}
	public List<CatelogModel> getBlackCategoryData() {
		return blackCategoryData;
	}
	public void setBlackCategoryData(List<CatelogModel> blackCategoryData) {
		this.blackCategoryData = blackCategoryData;
	}
	
	/**
	 * @创建：Tony 2016-3-29下午2:38:38
	 * @描述：讲json对象转换为JavaBean
	 * @param jObject
	 */
	public static OneKeyFilterResponseModel json2Model(JSONObject jObject){
		if(null == jObject){
			return null;
		}
		OneKeyFilterResponseModel model = new OneKeyFilterResponseModel();
		model.setCustomerID(jObject.optLong("CustomerID"));
		model.setFilter(jObject.optBoolean("IsFilter"));
		//白名单
		JSONArray whiteCategaryJSONArray = jObject.optJSONArray("WhiteCategoryData");
		if(null!=whiteCategaryJSONArray && whiteCategaryJSONArray.length()>0){
			List<CatelogModel> dataList = new ArrayList<CatelogModel>();
			for(int i =0;i<whiteCategaryJSONArray.length();i++){
				dataList.add(CatelogModel.json2ChildCategories(whiteCategaryJSONArray.optJSONObject(i)));
			}
			model.setWhiteCategoryData(dataList);
		}
		
		//黑名单
		JSONArray blackCategaryJSONArray = jObject.optJSONArray("BlackCategoryData");
		if(null!=blackCategaryJSONArray && blackCategaryJSONArray.length()>0){
			List<CatelogModel> dataList = new ArrayList<CatelogModel>();
			for(int i =0;i<blackCategaryJSONArray.length();i++){
				dataList.add(CatelogModel.json2ChildCategories(blackCategaryJSONArray.optJSONObject(i)));
			}
			model.setBlackCategoryData(dataList);
		}
		return model;
	}
}
